<template>
	<view class="tab">
		<view v-for="(item,index) in list" :key="index" class="tab-item" @click="switchTab(item, index)">
			<image class="tab_img" :src="currentIndex == index ? item.selectedIconPath : item.iconPath"></image>
			<view class="tab_text" :style="{color: currentIndex == index ? selectedColor : color}">{{item.text}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			selectedIndex: { // 当前选中的tab index
				default: 0
			},
		},
		data() {
			return {
				color: "#666666",
				selectedColor: "#00BAB2",
				list: [],
				currentIndex: 0,
			}
		},
		created() {
			this.currentIndex = this.selectedIndex;

			let _this = this
			if (uni.getStorageSync('identify')=='Coach') {
				//教练端
				this.list = [{
						"pagePath": "/pages/coach/home/anpai",
						"iconPath": "/static/home.png",
						"selectedIconPath": "/static/homeclick.png",
						"text": "课程安排"
					},
					{
						"pagePath": "/pages/coach/home/MyStudent",
						"iconPath": "/static/myTeacherClick.png",
						"selectedIconPath": "/static/myTeacher.png",
						"text": "我的学员"
					},
					{
						"pagePath": "/pages/coach/class/series",
						"iconPath": "/static/kecheng.png",
						"selectedIconPath": "/static/kechengji.png",
						"text": "我的课程"
					},
					{
						"pagePath": "/pages/coach/home/anli",
						"iconPath": "/static/anli.png",
						"selectedIconPath": "/static/anliclick.png",
						"text": "学员案例 "
					},
					{
						"pagePath": "/pages/coach/home/wode",
						"iconPath": "/static/my.png",
						"selectedIconPath": "/static/myclick.png",
						"text": "我的信息"
					}
				]
			} else {
				//学员端
				this.list = [{
						"pagePath": "/pages/student/index/index",
						"iconPath": "/static/icon/home.png",
						"selectedIconPath": "/static/icon/homeblue.png",
						"text": "首页"
					},
					{
						"pagePath": "/pages/student/index/class",
						"iconPath": "/static/icon/order.png",
						"selectedIconPath": "/static/icon/orderblue.png",
						"text": "约课"
					},
					{
						"pagePath": "/pages/student/index/my",
						"iconPath": "/static/icon/my.png",
						"selectedIconPath": "/static/icon/myblue.png",
						"text": "我的"
					}

				]
			}
		},
		methods: {
			switchTab(item, index) {
				console.log("--sucess--")
				this.currentIndex = index;
				let url = item.pagePath;
				console.log(item.pagePath)
				uni.redirectTo({url:url})
			}
		}
	}
</script>

<style lang="scss">
	.tab {
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		height: 90rpx;
		background: white;
		display: flex;
		justify-content: center;
		align-items: center;
		padding-bottom: env(safe-area-inset-bottom); // 适配iphoneX的底部

		.tab-item {
			margin-top: 25px;
			flex: 1;
			text-align: center;
			display: flex;
			justify-content: center;
			align-items: center;
			flex-direction: column;

			.tab_img {
				width: 50rpx;
				height: 50rpx;
			}

			.tab_text {
				font-size: 30rpx;
				margin-top: 9rpx;
			}
		}
	}
</style>